package com.erp.module.crm

import android.content.Context
import android.util.Log
import com.erp.Interface.OnUserDataInterface
import com.erp.bean.CrmSouSuoBean
import com.erp.contacts.Contacts
import com.erp.util.Httputil
import com.erp.util.Httputil.Call
import com.erp.util.Httputil.getparams
import com.erp.util.Sputil
import org.xutils.http.RequestParams
import org.xutils.x

/**
 * Created by Administrator on 2019/3/13/013.
 * 作者：刘洋
 */
class CrmModel : CrmContract.CrmMP {
    override fun setuserdatahttp(context: Context, page: Int, pagesize: Int, fields: Array<String>, souSuoBean: CrmSouSuoBean, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.USERDATA)
        getparams(context, params)
        Httputil.setProsess(params)
        params.addBodyParameter("page", page.toString())
        params.addBodyParameter("pagesize",pagesize.toString())
        for(i in 0 until fields.size){
            params.addBodyParameter("fields[$i]", fields[i])
        }
        params.addBodyParameter("searchParams[all]", souSuoBean.all)
        if(souSuoBean.xiaoshouyuan_uid != "") {
            params.addBodyParameter("searchParams[xiaoshouyuan_uid][1]", souSuoBean.xiaoshouyuan_uid)
        }
        if(souSuoBean.shejishi_uid != "") {
            params.addBodyParameter("searchParams[designer_uid][1]", souSuoBean.shejishi_uid)
        }
        params.addBodyParameter("searchParams[customer_name]", souSuoBean.kehuming)
        params.addBodyParameter("searchParams[customer_tel]", souSuoBean.shoujihao)
        params.addBodyParameter("searchParams[onum]", souSuoBean.shengchan)
        params.addBodyParameter("searchParams[contract_num]", souSuoBean.hetong)
        params.addBodyParameter("searchParams[status]", souSuoBean.status)
        if(souSuoBean.time_category != ""){
            params.addBodyParameter("searchParams[time_filter][time_category]", souSuoBean.time_category)
            params.addBodyParameter("searchParams[time_filter][start_time]", souSuoBean.start_time)
            params.addBodyParameter("searchParams[time_filter][end_time]", souSuoBean.end_time)
        }
        params.addHeader("ACCEPT", "application/json");
        x.http().get(params, Call(context, onUserDataInterface))
    }



}